package com.example.receiver;

import java.util.ArrayList;

import com.example.receiver.BlackgroupService.FeadData;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class GetData extends FragmentActivity {

	double getdatalat;
	double getdatalng;
	double emerlat;
	double emerlng;
	private LocationManager lm;
	GoogleMap myMap;
	public Context con;
	ArrayList<LatLng> mMarkerPoints = new ArrayList<LatLng>();// add
	public double latchange = 0;
	public double lngchange = 0;
	LatLng curpoint;
	LatLng despoint;
	Button accept;
	Button mainact;
	Intent bgserviceinternet;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.internetreceive);

		accept = (Button) findViewById(R.id.btnaccept);
	

		int status = GooglePlayServicesUtil
				.isGooglePlayServicesAvailable(getBaseContext());

		Log.v("Pongpon", "into class getData");

		if (status != ConnectionResult.SUCCESS) {

			int requestCode = 10;
			Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
					requestCode);
			dialog.show();
		}

		else {

			getdatalat = getIntent().getDoubleExtra("emerlat", emerlat);
			getdatalng = getIntent().getDoubleExtra("emerlng", emerlng);
			despoint = new LatLng(getdatalat, getdatalng);
			Log.d("getdatalat", "" + getdatalat);
			Log.d("des", "" + despoint);

			lm = (LocationManager) getSystemService(LOCATION_SERVICE);
			con = new GetData();
			GetCurLocation curlocation = new GetCurLocation(lm, this, myMap);
			latchange = curlocation.getMlat();
			Log.d("latchange", "" + latchange);
			lngchange = curlocation.getMlng();
			curpoint = new LatLng(latchange, lngchange);
			Log.d("curpoint", "" + curpoint);

			SupportMapFragment mySupport = (SupportMapFragment) getSupportFragmentManager()
					.findFragmentById(R.id.map_canvas);
			myMap = mySupport.getMap();
			myMap.setMyLocationEnabled(true);
			Router routerr1 = new Router(myMap, curpoint, despoint);
			Log.d("curpoint", "" + curpoint);
			Log.d("despoint", "" + despoint);

			accept.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
                 //   MainActivity.statusthread = true;
					BlackgroupService.isLooping = true;
					HttpPostUpdate post = new HttpPostUpdate();
					post.curpoint(getdatalat, getdatalng);
					post.posts
							.execute("http://172.16.149.122/myexample/update.php");

				}
			});
			
			
		}

	}


}
